package com.mycode.controller;

import com.mycode.domain.Payment;
import com.mycode.domain.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Created by Zengsh123 on 2020/3/9.
 */
@RestController
public class ConsumerController {

//    private static final String BASE_URL = "http://localhost:8001";

    // 向eureka注册中心去调服务
    private static final String BASE_URL = "http://CLOUD-PAYMENT-SERVICE";

    private final RestTemplate restTemplate;
    @Autowired
    public ConsumerController(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @GetMapping("/consumer/payment/get/{id}")
    public ResponseResult<Payment> get(@PathVariable("id") Long id){
        return restTemplate.getForObject(BASE_URL + "/payment/get/" + id, ResponseResult.class);
    }

    @GetMapping("/consumer/payment/insert")
    public ResponseResult get(Payment payment){
        return restTemplate.postForObject(BASE_URL + "/payment/insert",payment, ResponseResult.class);
    }
}
